
#include "USART.h"
#include "ex_eeprom.h"
#include "printf.h"
#include "PhoneNumbers.h"
#include "string.h"
#include "CmdMacros.h"
#include "Command.h"
#include "InputsHandlers.h"

unsigned char DirDescIndex;

/* typedef struct  */
/* { */
/* 		unsigned char Name[CMD_MACRO_NAME_SIZE+1]; */
/* 		unsigned char Macro[CMD_MACRO_COMMAND_SIZE+1]; */
	
/* }COMMAND_MACRO; */


void Macros_Print ( void )
{
	unsigned char i, Item = 0;
	unsigned int Address;

	COMMAND_MACRO	CmdMacro;
	
	printf("\r\r === List of Macros ===\r");
	
	//Ex_Directory[DirName].DirectioryName;
	
	Address = Ex_Directory[DirDescIndex].DirectioryName;

	for ( i = 0; i < Ex_Directory[DirDescIndex].EntryCount; i++ )
	{
		Ex_LoadFrom((unsigned char*)&CmdMacro, Address, Ex_Directory[DirDescIndex].EntrySize);
		
		if ( CmdMacro.Name[0] != 0xFF )
		{
			printf("\n%d. %s %s", ++Item, CmdMacro.Name, CmdMacro.Macro);
		}
	
		Address += Ex_Directory[DirDescIndex].EntrySize;
	}

	printf("\r\r === End of List \r\r");		
	
	Cmd_Return();
}


/* Ex_Directory[DIRECTORY__OWNERS_LIST].DirectioryName = EX_ADDR_LIST_OWNERS; */
/* 	Ex_Directory[DIRECTORY__OWNERS_LIST].EntryCount = COUNT_OWNERS; */
/* 	Ex_Directory[DIRECTORY__OWNERS_LIST].EntryNameSize = sizeof(Record_Customer.Phone); */
/* 	Ex_Directory[DIRECTORY__OWNERS_LIST].EntrySize = sizeof(Record_Customer); */
/* 	Ex_Directory[DIRECTORY__OWNERS_LIST].Print = List_Print; */

unsigned char b[24];

void  List_Print ( void )
{
	unsigned char i, Item = 0;
	unsigned int Address;
	RECORD_CUSTOMER Record_Customer;

	printf("\r\r === List of group #%d ===\r", DirDescIndex);
	
	//Ex_Directory[DirName].DirectioryName;
	
	Address = Ex_Directory[DirDescIndex].DirectioryName;

	for ( i = 0; i < Ex_Directory[DirDescIndex].EntryCount; i++ )
	{
		/* printf("\nEx_Directory[DirDescIndex].EntrySize: %d\n", Ex_Directory[DirDescIndex].EntrySize); */
		/* printf("Ex_Directory[DirDescIndex].EntryNameSize: %d\n", Ex_Directory[DirDescIndex].EntryNameSize); */

		Ex_LoadFrom((unsigned char*)&Record_Customer, Address, Ex_Directory[DirDescIndex].EntrySize);
		
		if ( Record_Customer.Phone[0] != 0xFF )
		{
			FlipFlopN(Record_Customer.Phone, Ex_Directory[DirDescIndex].EntryNameSize);

			BCDToStr(b, Record_Customer.Phone, Ex_Directory[DirDescIndex].EntryNameSize);
		 
			//printf("\n%d. %s %s", ++Item, str, Record_Customer.UserPassword);
			printf("\n%d. %s", i+1, b);
				  
		}
	
		Address += Ex_Directory[DirDescIndex].EntrySize;
	}

	printf("\r\r === End of List \r\r");

	Cmd_Return();
}


/* typedef struct */
/* { */
/* 		unsigned char InputName;  		/\* Input number *\/ */
/* 		unsigned char EventsOnEdge;/\* 'RISE'(1), 'FALL'(0), 'PULSE'(EventsOnEdge > 1), 'ANY CHANGE'(EventsOnEdge==0xFF)*\/ */
/* 		unsigned char Reserve; */
/* 		unsigned char Message[INPUTS_DESCRIPTOR_MESSAGES_COUNT][INPUTS_DESCRIPTOR_MESSAGE_SIZE+1]; */
/* }INPUTS_DESCRIPTOR;				  /\* Input event descriptor *\/ */


void InputDescr_Print ( void )
{
	unsigned char i, item=1;
	unsigned int Address;
	INPUTS_DESCRIPTOR id;

	printf("\r\r  === Input Descriptors ===\r");
	
	//Ex_Directory[DirName].DirectioryName;
	
	Address = Ex_Directory[DirDescIndex].DirectioryName;

	for ( i = 0; i < Ex_Directory[DirDescIndex].EntryCount; i++ )
	{
		Ex_LoadFrom((unsigned char*)&id, Address, Ex_Directory[DirDescIndex].EntrySize);
		
		if ( id.InputName != 0xFF )
		{
			printf("------ %d ------\n", item++);
			
			printf("InputName:    %d\n", id.InputName);
			printf("EventsOnEdge: %d\n", id.EventsOnEdge);
			if ( id.Message[0][0] != 0xFF )
			{
				printf("Message1: %s\n", id.Message[0]);
			}
			if ( id.Message[1][0] != 0xFF )
			{
				printf("Message2: %s\n", id.Message[1]);
			}
			if ( id.Message[2][0] != 0xFF )
			{
				printf("Message3: %s\n", id.Message[2]);
			}

			printf("---------------\n\n");
		}
	
		Address += Ex_Directory[DirDescIndex].EntrySize;
	}

	printf("  === End of List ===\r\r");

	Cmd_Return();
}
